package lab5Source;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import java.util.AbstractList;


import lab5Source.S_Message.msgtypes;
import java.util.ArrayList;

public class S_ChangeLadyColorCommand extends AbstractCommand {
	protected LadyBird lady;
	protected static final double factor = 1.2;
	protected ArrayList colors;
	protected Color colorBackup;
	
	public S_ChangeLadyColorCommand(LadyBird lady) {
		super();
		this.lady = lady;
		this.colors = new ArrayList<Color>();
		this.S_initColors(this.colors);		
	}

	@Override
	public void Execute() {
		this.colorBackup = lady.getColor();
		
		Iterator iterator = this.colors.iterator();
		
		Boolean found = false;
		while (iterator.hasNext() && !found) {
			Color current = (Color) iterator.next();
			if (current.equals(lady.getColor())) {
				found = true;
			}
		}
		
		Color newColor;
		if (found) {
			if (iterator.hasNext()) {
				newColor = (Color) iterator.next();
			} else {
				newColor = (Color) this.colors.get(0);
			}
		} else {
			System.out.println("Error: color not found in S_ChangeLadyColorCommand");
			return;
		}
		
		this.S_setThemAllNewColor(newColor);
	}

	@Override
	public void Unexecute() {
		this.S_setThemAllNewColor(this.colorBackup);
	}
	
	protected void S_setThemAllNewColor(Color color) {
		lady.setColors(color, lady.getDotColor());
		lady.setChanged();
		lady.notifyObservers(new S_Message(msgtypes.UPDATE_COLOR));
	}
	
	protected void S_initColors(AbstractList<Color> colors) {
		// colors.add(Color.black);
		colors.add(Color.blue);
		colors.add(Color.cyan);
		colors.add(Color.darkGray);
		colors.add(Color.gray);
		colors.add(Color.green);
		colors.add(Color.lightGray);
		colors.add(Color.magenta);
		colors.add(Color.pink);
		colors.add(Color.red);
		colors.add(Color.yellow);		
	}

}
